/*
分析当天需要下载的文件
*/
package analyze

import (
	"github.com/astaxie/beego/logs"
	"monkeyCode/ftp/conn"
	"os"
	"time"
)

type FtpFile struct {
	Time string
	Dir string
	FileName string
}

var (
	PendingChan = make(chan *FtpFile,1000)
)


func GetTodayFiles(){
	for {
		logs.Info("开始扫描待下载文件列表")
		todayStr := time.Now().Format("20060102")
		yestodayStr := time.Now().AddDate(0,0,-1).Format("20060102")
		//创建目录
		err := os.MkdirAll(conn.Conf.Dir +"/"+todayStr+"/release/",os.ModePerm)
		err = os.MkdirAll(conn.Conf.Dir +"/"+yestodayStr+"/release/",os.ModePerm)
		if err!=nil{
			logs.Error("无法创建文件的保存目录,%s",conn.Conf.Dir +"/"+todayStr)
			os.Exit(1)
		}
		for _,v := range conn.Conf.DictRule{
			for _,v2 := range conn.Conf.FileRule{
				f1 := FtpFile{Time:todayStr,Dir:"gfs."+todayStr+v,FileName:"gfs.t"+v+"z.pgrb2.0p50.f0"+v2}
				f2 := FtpFile{Time:yestodayStr,Dir:"gfs."+yestodayStr+v,FileName:"gfs.t"+v+"z.pgrb2.0p50.f0"+v2}
				PendingChan <- &f1
				PendingChan <- &f2
			}
		}
		time.Sleep(time.Minute*2)
	}

}
